package cn.manyufun.myf.ui.comics.presenter;

import cn.manyufun.myf.R;
import cn.manyufun.myf.app.AppConstant;
import cn.manyufun.myf.bean.BaseBean;
import cn.manyufun.myf.bean.ComicsDetailBean;
import cn.manyufun.myf.common.baserx.RxSubscriber;
import cn.manyufun.myf.common.commonutils.LogUtils;
import cn.manyufun.myf.ui.comics.contract.ComicsDetailContract;
import rx.functions.Action1;

/**
 * Created by Xiao on 2018-02-06.
 */

public class ComicsDetailPresenter extends ComicsDetailContract.Presenter {
    @Override
    public void onStart() {
        super.onStart();
        //新增说说监听
        mRxManage.on(AppConstant.COMICS_EDIT_COMMENT_OR_ARTICLE, new Action1<BaseBean>() {
            @Override
            public void call(BaseBean baseBean) {
                mView.reloadComicsDetail();
            }
        });
    }

    @Override
    public void getComicsDetailDataRequest(long comicsid) {
        mRxManage.add(mModel.getComicsDetailData(comicsid)
                .subscribe(new RxSubscriber<ComicsDetailBean>(mContext, false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }

                    @Override
                    protected void _onNext(ComicsDetailBean comicsDetailBean) {
                        mView.returnComicsDetailData(comicsDetailBean);
                        mView.stopLoading();
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.showErrorTip(message);
                    }
                }));
    }

    @Override
    public void followComicsRequest(final int actionType, long comicsId) {
        mRxManage.add(mModel.followComics(actionType, comicsId)
                .subscribe(new RxSubscriber<BaseBean>(mContext, false) {
                    @Override
                    public void onStart() {
                        super.onStart();
                        mView.showLoading(mContext.getString(R.string.loading));
                    }

                    @Override
                    protected void _onNext(BaseBean baseBean) {
                        LogUtils.logd("follownext" + actionType);
                        mView.returnFollowComics(baseBean, actionType);
                        mView.stopLoading();
                    }

                    @Override
                    protected void _onError(String message) {
                        mView.showErrorTip(message);
                    }
                }));
    }
}
